using ASP;
using HoWave.Common;
using HoWave.Data;
using HoWave.Data.Bll;
using HoWave.Data.Model;
using HoWave.Web.Admin;
using System;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;
public class Admin_MBF_UserGiftCardFestivalEdit : Admin, IRequiresSessionState
{
	protected HiddenField h_id;
	protected DropDownList ddl_FestivalType;
	protected RequiredFieldValidator RequiredFieldValidator1;
	protected TextBox txtFestivalName;
	protected RequiredFieldValidator rfv1;
	protected TextBox txtBeginTime;
	protected TextBox txtEndTime;
	protected Button Add;
	protected Button ButtonReturn;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!this.Page.IsPostBack)
		{
			if (!base.admin.CheckAdminPower(39))
			{
				base.WriteLog("Modidy", Language.GetAdminMsg("Log/Access", "0"), "MBF_UserGiftCardFestivalEdit");
				base.WriteRightErrMsg();
			}
			this.txtBeginTime.Attributes.Add("onClick", "SelectDate(" + this.txtBeginTime.UniqueID + ",'MM-dd');");
			this.txtEndTime.Attributes.Add("onClick", "SelectDate(" + this.txtEndTime.UniqueID + ",'MM-dd');");
			string text = Fetch.Get("id");
			if (text != "")
			{
				this.ShowInfo(text);
			}
		}
	}
	private void ShowInfo(string id)
	{
		UserGiftCardFestivalModel model = Blls.bllFestival.GetModel(id);
		this.h_id.Value = (this.txtFestivalName.Text = model.FestivalName);
		this.ddl_FestivalType.ddlSelect(model.FestivalType.ToString());
	}
	protected void ButtonReturn_Click(object sender, EventArgs e)
	{
		base.Response.Redirect("MBF_UserGiftCardFestivalSet.aspx?MenuName=卡类管理&FileName=礼品卡节日管理#pos_" + this.h_id.Value);
	}
	protected void Add_Click(object sender, EventArgs e)
	{
		try
		{
			string text = "";
			if (this.txtFestivalName.Text.Trim() == "")
			{
				text += "请填写节日名称！\\n";
			}
			if (this.ddl_FestivalType.GetSelectValue(new string[0]) == "1")
			{
				if (this.txtBeginTime.Text.Trim() == "")
				{
					text += "请选择节日开始时间！\\n";
				}
				if (this.txtEndTime.Text.Trim() == "")
				{
					text += "请选择节日结束时间！\\n";
				}
			}
			if (text != "")
			{
				MessageBox.Show(this, text);
			}
			else
			{
				UserGiftCardFestivalModel userGiftCardFestivalModel = new UserGiftCardFestivalModel();
				userGiftCardFestivalModel.FestivalName = this.txtFestivalName.Text.Trim();
				userGiftCardFestivalModel.FestivalBegin = new DateTime?(Convert.ToDateTime(DateTime.Now.Year + "-" + this.txtBeginTime.Text));
				userGiftCardFestivalModel.FestivalEnd = new DateTime?(Convert.ToDateTime(DateTime.Now.Year + "-" + this.txtEndTime.Text));
				userGiftCardFestivalModel.FestivalType = new int?(this.ddl_FestivalType.GetSelectValue(new string[0]).ToInt32(new int[0]));
				if (this.h_id.Value == "")
				{
					Blls.bllFestival.Add(userGiftCardFestivalModel);
				}
				else
				{
					Blls.bllFestival.Update(userGiftCardFestivalModel);
				}
				this.WriteSuccessMsg("", "保存成功！", "MBF_UserGiftCardFestivalSet.aspx?MenuName=卡类管理&FileName=礼品卡节日管理#pos_" + userGiftCardFestivalModel.FestivalName);
			}
		}
		catch (Exception)
		{
			MessageBox.Show(this, "保存出错！");
		}
	}
}
